<?php


namespace app\admin\controller;
use app\common\model\Recording;
use app\common\services\NotesService;

class MoneyTz extends Common
{
    /**
     * 用户金额调整
     */
    public function index()
    {
        if (is_post()) {
            $tel = input('post.us_tel');
            $money = input('post.money');
            if (empty($tel)) {
                return ['code' => 0, 'msg' => '手机号不能为空'];
            }
            $phone = model('user')->where('us_tel', $tel)->count();
            if ($phone != 1) {
                return ['code' => 0, 'msg' => '该用户不存在'];
            }
            if ($money ==0){
                return ['code' => 0, 'msg' => '充值金额不能为0'];
            }
            $adminInfo = Session('admin');
//            halt($adminInfo);
            $yuan_money = model('user')->where('us_tel',$tel)->value('us_all_get');
            $tz = model('user')->where('us_tel', $tel)->setInc('us_all_get', $money);
            $over_money = model('user')->where('us_tel', $tel)->value('us_all_get');
            $data = [
                'type' => 2,
                'tel' => $tel,
                'yuan_money' => $yuan_money,
                'content' => '后台金额调整',
                'chongzhi_money' => $money,
                'over_money' => $over_money
            ];
            $notes = new NotesService();
            $msg =  $notes->index($adminInfo, $data);
            if ($msg['code']==1 && $tz ){
                return ['code'=>1,'msg'=>'充值成功'];
            }else{
                return ['code'=>0,'msg'=>'充值失败'];
            }
        }

        return $this->fetch();
    }

    //  充值记录
    public function notes()
    {
        if (input('get.name')) {
            $this->map[] = ['admin_user_name|chongzhi_ren', 'like', '%'.input('get.name').'%'];
        }
        if (is_numeric(input('get.or_status'))) {
            $this->map[] = ['admin_user_identity', '=', input('get.or_status')];
        }
        if (input('get.start') && input('get.end') == "") {
            $this->map[] = ['edit_time', '>=', input('get.start')];
        }
        if (input('get.start') == "" && input('get.end')) {
            $this->map[] = ['edit_time', '=<', input('get.end')];
        }
        if (input('get.start') && input('get.end')) {
            $this->map[] = ['edit_time', 'between', array(input('get.start'), input('get.end'))];
        }
        $this->map[] = ['type','=',2];
        $show_data = Recording::show($this->map);
        $this->assign('list',$show_data);
        return $this->fetch();
    }

}